//商品
(function() {
	var db = require("../db/index");
	var config = require("../_include/config");
	var db_table_name = config.dbname.dotnarNews;
	var db_id_prefix = config.dbIdPrefix.dotnarNews;
	var helper = require("../_include/helper");
	//构造函数
	var _con = function(info, bus_id, num) {
		var self = this;
		//商品编号
		self._id = db_id_prefix + Math.random().toString(16).substr(2) + (+new Date).toString(16);

		// //额外信息，包括所需价格与所需积分
		self.info = {};
		self._initInfo(info);

		//创建时间
		self.createTime = +new Date;

		db.insert(db_table_name, self);
		console.log("生成了一个动态新闻：", info.title);

	};
	//技能
	module.exports = _con;
	_con.prototype = require("./skill");
	//静态方法
	_con.get = function(Id) {
		var result = db.find_by_id(db_table_name, Id);
		if (result) {
			result.__proto__ = _con.prototype;
		}
		return result;
	}
	//获取全部动态新闻
	_con.getAll = function(num, page) {
		var dotnar_news_list = db.find_all(db_table_name);
		dotnar_news_list = data_cut.page(dotnar_news_list, num, page)
		dotnar_news_list.forEach(function(dotnar_news) {
			dotnar_news.__proto__ = _con.prototype;
		});
		//按时间排序
		return dotnar_news_list.sort(function(news_a, news_b) {
			return news_a.createTime < news_b.createTime;
		});
	}
	var BuffsCon = require("../buff/_con");
	var BusCon = require("../bus/_con");
	var data_cut = require("../_include/data_cut");
}());